package com.kgc.service.edu.controller;


import com.github.pagehelper.PageInfo;
import com.kgc.common.result.Result;
import com.kgc.service.edu.entity.SieRole;
import com.kgc.service.edu.entity.SieUser;
import com.kgc.service.edu.entity.vo.SieInfo;
import com.kgc.service.edu.service.SieRoleService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/edu/sie-role")
public class SieRoleController {
    private SieRoleService sieRoleService;

    public SieRoleController(SieRoleService sieRoleService) {
        this.sieRoleService = sieRoleService;
    }

    @PostMapping("{current}/{size}")
    @ApiOperation(value = "分页")
    public Result page(@ApiParam("当前页") @PathVariable("current") Integer current,
                       @ApiParam("每页显示条数") @PathVariable("size") Integer size
            , @ApiParam("查询对象") @RequestBody SieRole sieRole) {
        System.out.println(sieRole);
        PageInfo<SieRole> pageInfo = sieRoleService.selRole(sieRole, current, size);

        // 1.获取总记录数
        long total = pageInfo.getTotal();
        // 2.获取所有数据
        List<SieRole> sieRoles = pageInfo.getList();
        int size1 = pageInfo.getSize();
       /* Map<String, Object> map = new HashMap();
        map.put("total", total);
        map.put("items", teachers);
        return Result.ok().setData(map);*/
        return Result.ok().setData("total", total).setData("items", sieRoles);
    }

    @PostMapping("/save")
    public Result saveSieInfo(@RequestBody SieRole sieRole){
        //System.out.println(sieInfo);
        int id = sieRoleService.saveSieRole(sieRole);
        return Result.ok().setData("item",id);
    }

    @PostMapping("/update")
    public Result updateSieRoleById(@RequestBody SieRole sieRole){
        System.out.println(sieRole);
        sieRoleService.updateSieRole(sieRole);

        return  Result.ok();
    }

    @GetMapping("{id}")
    public Result getSieRoleById(@PathVariable String id) {

        SieRole sieRole = sieRoleService.selectSieRoleByid(id);
        return sieRole != null ? Result.ok().setData("item", sieRole)
                : Result.error().setMessage("数据不见了");
    }

    @DeleteMapping("{ids}")
    public Result delSieById(@RequestBody List<String> ids){
        //System.out.println(id);
        System.out.println(ids);
        int del=sieRoleService.delectRoleById(ids);
        return Result.ok().setData("item",del);
    }
}
